<?php

namespace App\Http\Requests;

use App\Rules\NumericRule;
use Illuminate\Foundation\Http\FormRequest;

class ProductRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'openid' => 'required',
            'cate_id' => 'required|numeric',
            'name' => 'required',
            'detail' => 'nullable|max:255',
            'price' => 'required|numeric',
            'stock' => 'nullable|numeric',
            'type' => ['nullable','numeric',new NumericRule],
        ];
    }

    public function messages()
    {
        return [
            'name.required' => '请添加商品名称',
            'price.required' => '请添加商品价格',
        ];
    }

}
